<?php

namespace app\common\model\Business;

use think\Model;

class Receive extends Model
{
    // 设置该模型对应哪个数据库表
    protected $name = "business_receive";

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 设置时间戳字段名
    protected $createTime = 'applytime';

    // 设置不更新时间戳
    protected $updateTime = false;

    protected $append = [
        'status_text', //  申请状态
    ];

    public function getStatusTextAttr($value, $data)
    {
        $map = [
            'apply' => '申请',
            'allot' => '分配',
            'recovery' => '回收',
            'reject' => '拒绝'
        ];

        return $map[$data['status']];
    }

    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'applyid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function business()
    {
        return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
